package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController("adminShopController")
@Slf4j
@RequestMapping("/admin/shop")
@Api(tags = "店铺控制器")
public class ShopController {
    @Resource
    private RedisTemplate redisTemplate;
    private final String SHOP_STATUS = "SHOP_STATUS";
    // 方法三要素
    // 设置营业状态
    @PutMapping("/{status}")
    @ApiOperation("设置营业状态")
    public Result<String> setStatus(@PathVariable Integer status){
        log.info("[设置营业状态] status:{}",status);
        // 操作redis  string
        redisTemplate.opsForValue().set(SHOP_STATUS,status);
        return Result.success();
    }
    @GetMapping("/status")
    @ApiOperation("获取营业状态")
    public Result<Integer> getStatus(){
        // 读取redis
        Object status = redisTemplate.opsForValue().get(SHOP_STATUS);
        // 0 打烊  1营业
        return status!=null ? Result.success((Integer)status) : Result.success(0);
    }
}
